#include"process.h"
#include<stdlib.h>
#include<time.h>

typedef void (*flush_t)(double total, double current);// 这是一个刷新的函数指针类型

const int base =10;
double total = 2048.0;//2048MB
double once  = 0.1;   //0.1MB

void download(flush_t f)
{
  double current = 0.0;
  while(current < total)
  {
     //模拟下载过程
     int r = rand()%base+1; //1到10
     double speed =r*once;
     current += speed;
     if(current > total ) current =total;
     usleep(1000); 
   
     //进行图像化实时刷新展示  
     f(current,total);
  }
  printf("\n");
}

int main()
{
  srand(time(NULL));
  download(FlushProcess); 
  download(FlushProcess); 
  download(FlushProcess); 
  download(FlushProcess); 
  download(FlushProcess); 
  download(FlushProcess); 
  return 0;
}
